/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_serialize_hessian2_readobject.c                  */
/*  NOTE      =                                                    */
/*  DATE      = 2017/01/19 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include <dubbo/dubbo_serialize_dubbo.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "../../../../src/module/dubbo/config.h"

extern int serialize_hessian2_readobject(Frbyte_Packet *p_packet, L7session_dubbo_private *p_st_private, Frreport_body_data *p_st_body_data, char *p_name);

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

static void case1(void)
{
    Frbyte_Packet *p_packet = NULL;
    L7session_dubbo_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    int i_ret = 0;

    i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, NULL);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}

static void case2(void)
{
    Frbyte_Packet *p_packet = NULL;
    L7session_dubbo_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    int i_ret = 0;
    char *p_data = NULL;

    p_data = (char *)"\x4e";
    p_packet = bytebuff_creat();
    if(p_packet == NULL)
        goto ERROR;
    if(bytebuff_add(p_packet, p_data, 2) != FR_SUCC)
        goto ERROR;

    p_st_private = (L7session_dubbo_private *)frmalloc(sizeof(L7session_dubbo_private));
    if(p_st_private == NULL)
        goto ERROR;
    memset(p_st_private, 0x00, sizeof(L7session_dubbo_private));

    p_st_body_data = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    if(p_st_body_data == NULL)
        goto ERROR;
    memset(p_st_body_data, 0x00, sizeof(Frreport_body_data));
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, (char *)"request.rpc.arg");

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    bytebuff_free(&p_packet);
    dubbo_session_destroy(p_st_private);
    frreport_body_free(&p_st_body_data);

    return;

ERROR:
    if(p_packet)
        bytebuff_free(&p_packet);
    if(p_st_body_data)
        frreport_body_free(&p_st_body_data);
    return;
}

int add_suite_serialize_hessian2_readobject(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" serialize_hessian2_readobject()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL || 
        CU_add_test(pSuite, "case2", case2) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
